<template>
  <div class="page-header-index-wide">
    <a-row :gutter="24" style="margin-top: 20px">
      <a-col :sm="24" :md="4" :xl="24">
        <a-card class="box1" style="height: 180px">
          <img
            v-if="infoData.headUrl == null"
            style="width: 130px; height: 130px; border-radius: 15px; float: left"
            src="~@/assets/icon/u18916.png"
            alt=""
          />
          <img
            v-else
            style="width: 130px; height: 130px; border-radius: 15px; float: left"
            :src="'data:image/png;base64,' + infoData.headUrl"
            alt=""
          />
          <div style="float: left">
            <div class="s s1">
              <span>{{ infoData.infoCode }}</span>
              <a-tag color="red" style="margin-left: 50px">{{ infoData.sourceType }}</a-tag>
            </div>
            <!-- <div class="s s2">
              情报名称: <span>{{ infoData.name }}</span>
              <a-tag style="margin-left: 50px">{{ infoData.goodsType }}</a-tag>
            </div> -->
            <div class="s s2">
              情报名称: <span v-html="highLightKeywords(infoData.name, brandList)"></span>
              <a-tag v-if="sourceType == 1" style="margin-left: 50px">{{ infoData.goodsType }}</a-tag>
            </div>
            <!-- <span class="qbTitle" v-html="highLightKeywords(text, Keywords)"></span> -->
            <div class="s s3">
              <span>账户名ID：{{ infoData.userId }}</span>
              <span>发布时间：{{ infoData.publishedTime }}</span>
              <span>发布地点：{{ infoData.publishedArea }}</span>
              <span v-if="sourceType == 2">发布作者：{{ infoData.publishedAuthor }}</span>
              <span>推送时间：{{ infoData.pushTime }}</span>
            </div>
            <div class="s s3">
              <span>原文链接：{{ infoData.sourceUrl }}</span>
              <template v-if="sourceType == 1">
                <span>店铺类型：{{ infoData.shopType }}</span>
                <span>销售：{{ infoData.saleNum }}</span>
                <span> 数量：{{ infoData.goodsNum }}</span>
                <span>商品价格：¥ {{ infoData.goodsPrice }}</span>
              </template>
            </div>
          </div>
        </a-card>
      </a-col>
    </a-row>
    <a-row :gutter="24" style="margin-top: 20px">
      <a-col :sm="24" :md="4" :xl="16">
        <a-card style="height: 630px" class="box2">
          <!-- <img src="https://www.baidu.com/img/bd_logo1.png" />
          <img src="https://up.enterdesk.com/edpic/12/46/04/124604e4cf8e68bcd149d147ef43f0fd.jpg" />
          <img src="./img/aa.jpg" /> -->
          <!-- <p v-if="sourceType == 1" class="p1">情报名称：</p>
          <p v-if="sourceType == 1" class="p2">{{ infoData.name }}</p> -->
          <p v-if="sourceType == 1" class="p1">商品详情内容：</p>
          <p v-if="sourceType == 2" class="p1">发帖内容：</p>
          <p class="p3">{{ infoData.infoContent }}</p>
          <!-- <p v-if="sourceType == 1" class="p1">情报图片：</p> -->
          <p v-if="sourceType == 2 && imgListLen > 0" class="p1" style="border-top: 1px dotted #ccc; padding-top: 20px">
            发帖图片：
          </p>
          <div class="carouselBox" v-if="imgListLen > 0">
            <a-carousel arrows>
              <div slot="prevArrow" slot-scope="props" class="custom-slick-arrow" style="left: -24px; zindex: 1">
                <a-icon type="left" />
              </div>
              <div slot="nextArrow" slot-scope="props" class="custom-slick-arrow" style="right: -24px">
                <a-icon type="right" />
              </div>
              <div v-for="(item, key) in imgArr" :key="key">
                <div v-for="(item2, key) in item.imgs" :key="key" class="hotBox">
                  <img :src="'data:image/png;base64,' + item2.src" style="cursor: pointer" preview="1" />
                </div>
              </div>
            </a-carousel>
          </div>
        </a-card>
      </a-col>
      <a-col :sm="24" :md="4" :xl="8">
        <a-card title="提取联系方式" style="height: 210px" class="tqlxfs">
          <p class="wx">
            <span class="s1">微信号</span><span>{{ infoData.wechatId }}</span>
          </p>
          <p class="sj">
            <span class="s1">手机号</span><span>{{ infoData.telephone }}</span>
          </p>
          <p class="QQ">
            <span class="s1">QQ号</span><span>{{ infoData.qq }}</span>
          </p>
          <!-- <a-tag style="margin-top: 10px" v-for="item in infoData.fzVictimTotalList" :key="item.id">
            {{ item.fraudType }}:{{ item.totalNum }}
          </a-tag> -->
        </a-card>
        <a-card title="关键词高频词" style="height: 400px; margin-top: 20px">
          <wordCloud :wordData="keywordData" title="" />
        </a-card>
      </a-col>
    </a-row>
    <a-row :gutter="24" style="margin-top: 20px">
      <a-col :sm="24" :md="4" :xl="16">
        <a-card style="height: 500px; margin-bottom: 20px" class="box3">
          <p class="p1">
            累计评价数 <span>{{ replyListData.total }}</span> 条
            <em v-if="sourceType == 2"
              >（累计转发 <span>{{ infoData.transmitNum }}</span> 条）</em
            >
          </p>
          <ReplyList :replyList="replyListData" @onRefreshTable="getReplyList" style="border-top: 1px solid #e8e8e8" />
        </a-card>
      </a-col>
      <a-col :sm="24" :md="4" :xl="8">
        <a-card title="图片提取文字" style="height: 500px; margin-bottom: 20px;overflow-y: scroll;" class="textBox">
          <template v-for="(item, key) in imgText">
            <p class="sp1" :key="key">{{ item }}</p>
          </template>
        </a-card>
      </a-col>
    </a-row>
    <a-row :gutter="24" v-if="module == 1">
      <a-col :span="24">
        <a-card title="告警分布图谱" style="height: 600px; margin-bottom: 20px">
          <radiationChart :chartData="chartData" />
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import wordCloud from '@/components/echarts/wordCloud.vue'
import ReplyList from '@/views/smuggle/components/ReplyList'
import radiationChart from './radiationChart'
import * as informationApi from '@/api/information.js'
import * as alarmApi from '@/api/alarm.js'
export default {
  name: 'detail',
  components: {
    ReplyList,
    radiationChart,
    wordCloud,
  },
  data() {
    return {
      infoData: {},
      pageFilter: {
        pageNo: 1, // 当前页数
        pageSize: 10, // 每页显示几条数据
        id: this.$route.query.id,
      },
      imgArr: [
        // {
        //   imgs: [
        //     {
        //       src: 'https://www.baidu.com/img/bd_logo1.png',
        //     },
        //     {
        //       src: 'https://www.baidu.com/img/bd_logo1.png',
        //     },
        //     {
        //       src: 'https://www.baidu.com/img/bd_logo1.png',
        //     },
        //     {
        //       src: 'https://www.baidu.com/img/bd_logo1.png',
        //     },
        //     {
        //       src: 'https://www.baidu.com/img/bd_logo1.png',
        //     },
        //   ],
        // },
        // {
        //   imgs: [
        //     {
        //       src: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1672984128,966606357&fm=26&gp=0.jpg',
        //     },
        //     {
        //       src: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1672984128,966606357&fm=26&gp=0.jpg',
        //     },
        //     {
        //       src: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1672984128,966606357&fm=26&gp=0.jpg',
        //     },
        //     {
        //       src: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1672984128,966606357&fm=26&gp=0.jpg',
        //     },
        //     {
        //       src: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1672984128,966606357&fm=26&gp=0.jpg',
        //     },
        //   ],
        // },
      ],
      keywordData: [],
      replyListData: {},
      imgText: [],
      // chartData: {
      //   id: 'Modeling Methods',
      //   children: [
      //     {
      //       id: 'Classification',
      //       children: [
      //         {
      //           id: 'Logistic regression',
      //         },
      //         {
      //           id: 'Linear discriminant analysis',
      //         },
      //         {
      //           id: 'Rules',
      //         },
      //         {
      //           id: 'Decision trees',
      //         },
      //         {
      //           id: 'Naive Bayes',
      //         },
      //         {
      //           id: 'K nearest neighbor',
      //         },
      //         {
      //           id: 'Probabilistic neural network',
      //         },
      //         {
      //           id: 'Support vector machine',
      //         },
      //       ],
      //     },
      //     {
      //       id: 'Consensus',
      //       children: [
      //         {
      //           id: 'Models diversity',
      //           children: [
      //             {
      //               id: 'Different initializations',
      //             },
      //             {
      //               id: 'Different parameter choices',
      //             },
      //             {
      //               id: 'Different architectures',
      //             },
      //             {
      //               id: 'Different modeling methods',
      //             },
      //             {
      //               id: 'Different training sets',
      //             },
      //             {
      //               id: 'Different feature sets',
      //             },
      //           ],
      //         },
      //         {
      //           id: 'Methods',
      //           children: [
      //             {
      //               id: 'Classifier selection',
      //             },
      //             {
      //               id: 'Classifier fusion',
      //             },
      //           ],
      //         },
      //         {
      //           id: 'Common',
      //           children: [
      //             {
      //               id: 'Bagging',
      //             },
      //             {
      //               id: 'Boosting',
      //             },
      //             {
      //               id: 'AdaBoost',
      //             },
      //           ],
      //         },
      //       ],
      //     },
      //     {
      //       id: 'Regression',
      //       children: [
      //         {
      //           id: 'Multiple linear regression',
      //         },
      //         {
      //           id: 'Partial least squares',
      //         },
      //         {
      //           id: 'Multi-layer feedforward neural network',
      //         },
      //         {
      //           id: 'General regression neural network',
      //         },
      //         {
      //           id: 'Support vector regression',
      //         },
      //       ],
      //     },
      //   ],
      // },
      chartData: null,
      sourceType: '',
      module: this.$route.query.module, //告警动态详情才有显示图谱
      imgListLen: 0,
      brandList: [],
    }
  },
  mounted() {
    this.getBrandList()
    this.getData()
  },
  methods: {
    getReplyList(params) {
      if (params != undefined) {
        this.pageFilter.pageNo = params.currentPage
        this.pageFilter.pageSize = params.pageSize
      }
      this.getData()
    },
    getBrandList() {
      informationApi
        .brandList(this.pageFilter)
        .then((res) => {
          if (res.success) {
            this.brandList = res.result.names
          }
        })
        .catch((e) => {
          // this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    getChartData(infoWarnId) {
      var param = {
        infoWarnId: infoWarnId,
      }
      alarmApi
        .queryWarnDistribution(param)
        .then((res) => {
          if (res.success) {
            this.$nextTick(() => {
              this.chartData = res.result
            })
          }
        })
        .catch((e) => {
          this.$message.warn('请求失败！')
        })
    },
    /**
     * 匹配每一个关键字字符
     * @param {Object} text 内容
     * @param {Object} keyword 关键词
     * @param {Object} tag 被包裹的标签
     */
    highLightKeywords(text, words, tag) {
      tag = tag || 'span' // 默认的标签，如果没有指定，使用span
      var i,
        len = words.length,
        re
      for (i = 0; i < len; i++) {
        // 正则匹配所有的文本
        re = new RegExp(words[i], 'g')
        if (re.test(text)) {
          text = text.replace(re, '<' + tag + ' class="highlight">$&</' + tag + '>')
        }
      }
      return text
    },
    spArray(N, Q) {
      var R = [],
        F
      for (F = 0; F < Q.length; ) {
        R.push(Q.slice(F, (F += N)))
      }
      return R
    },
    getData() {
      var module = this.$route.query.module
      var api
      if (module && module == 1) {
        api = alarmApi.queryWarnDetails(this.pageFilter)
      } else {
        api = informationApi.queryByInfoCode(this.pageFilter)
      }
      api
        .then((res) => {
          if (res.success) {
            this.infoData = res.result.smuInfoRecordDto
            if (
              this.infoData.sourceType == '淘宝' ||
              this.infoData.sourceType == '闲鱼' ||
              this.infoData.sourceType == '其他'
            ) {
              this.sourceType = 1
            } else {
              this.sourceType = 2
            }
            // 内容图片轮播数据处理
            this.imgListLen = this.infoData.imgList.length
            if (this.imgListLen > 0) {
              //5个按顺序分组
              let arr = this.spArray(5, this.infoData.imgList)
              arr.forEach((item1) => {
                let obj1 = {}
                let obj2 = {}
                let imgs = []
                item1.forEach((item2) => {
                  obj1['src'] = item2.imgUrl
                  imgs.push(obj1)
                })
                obj2['imgs'] = imgs
                this.imgArr.push(obj2)
              })
              // console.log(this.imgArr)
            }
            //高频词处理
            let keywordArr = this.infoData.keyword.split(',')
            keywordArr.forEach((item, index) => {
              this.keywordData.push({
                name: item,
                value: index,
              })
            })

            //图片提取文字
            if (this.infoData.imgText != null) {
              this.imgText = this.infoData.imgText.split('/n')
            }

            //聊天记录
            this.replyListData = res.result.smuInfoChatDtoPage

            if (module && module == 1) {
              this.getChartData(res.result.infoWarnId)
            }
            // this.loading = false
          } else {
            // this.loading = false
          }
        })
        .catch((e) => {
          // this.loading = false
          this.$message.warn('请求失败！')
        })
    },
  },
}
</script>

<style lang="less" scoped>
/deep/ .ant-card-head-title {
  font-weight: bold;
}
.box1 {
  position: relative;
  img {
    width: 40px;
    height: 40px;
  }
  .s {
    padding-bottom: 10px;
  }
  .s1 {
    margin-left: 20px;
    font-size: 20px;
    font-weight: bold;
  }
  .s2 {
    margin-left: 20px;
    font-size: 16px;
    // font-weight: bold;
  }
  .s3 {
    margin-left: 20px;
    font-size: 12px;
    // font-weight: bold;
    span {
      margin-right: 30px;
    }
  }
}
.box2,
.box3 {
  .p1 {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 10px;
    span {
      color: #02a7f0;
    }
  }
  .p2 {
    font-size: 14px;
    padding-bottom: 20px;
    border-bottom: 1px dotted #ccc;
  }
  .p3 {
    font-size: 14px;
    padding-bottom: 20px;
    line-height: 30px;
    word-wrap: break-word;
    word-break: break-all;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 10px;
  }
  em {
    font-style: normal;
  }
}
.textBox {
  .sp1 {
    margin-left: 20px;
    float: left;
  }
  // .sp1:nth-child(4n+1){
  //   margin-left: 0;
  // }
}
.tqlxfs {
  .s1 {
    border-radius: 5px;
    padding: 3px 6px;
    margin-right: 20px;
    display: inline-block;
    text-align: center;
    width: 60px;
  }
  .wx {
    color: #f29821;
    .s1 {
      border: 1px solid #f29821;
    }
  }
  .sj {
    color: #027db4;
    .s1 {
      border: 1px solid #027db4;
    }
  }
  .QQ {
    color: #ec808d;
    .s1 {
      border: 1px solid #ec808d;
    }
  }
}

/deep/.ant-timeline-item {
  left: 150px;
  .time {
    position: absolute;
    left: -160px;
  }
  .count {
    position: absolute;
    right: 400px;
    color: #f48093;
    border: 1px solid #f48093;
    padding: 2px 15px;
  }
  .type {
    position: absolute;
    right: 200px;
  }
  .ant-timeline-item-content {
    border-bottom: 1px dotted #ccc;
    padding-bottom: 20px;
  }
}
/deep/.ant-timeline-item-last > .ant-timeline-item-content {
  min-height: 0;
}

.carouselBox .ant-carousel .slick-slide {
  height: 250px;
  overflow: hidden;
  background: #fff;
}
.carouselBox .ant-carousel .slick-slide .hotBox {
  width: 17%;
  float: left;
  margin-left: 2.5%;
}
.carouselBox .ant-carousel .slick-slide .hotBox img {
  width: 100%;
  // height: 200px;
  cursor: pointer;
}
.carouselBox .ant-carousel .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #000;
  // background-color: rgba(31, 61, 35, 0.11);
  opacity: 0.5;
}
.carouselBox .ant-carousel .custom-slick-arrow:before {
  display: none;
}
.carouselBox .ant-carousel .custom-slick-arrow:hover {
  opacity: 0.7;
}
/deep/.highlight {
  color: #f7a945;
}
/deep/.ant-layout-content {
  overflow: hidden !important;
}
.modalImg {
  width: 650px;
}
</style>
